package edu.wuster.blog.controller;


import edu.wuster.blog.entity.Result;
import edu.wuster.blog.service.CommentService;
import edu.wuster.blog.entity.Comment;
import edu.wuster.blog.entity.Reply;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;



@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/addComment")
    public Result addComment(@RequestBody Comment comment){
        log.info("新增评论请求");
        commentService.addComment(comment);
        log.info("新增评论成功");
        return Result.success();
    }

    @PostMapping("/addReply")
    public Result addReply(@RequestBody Reply reply){
        log.info("新增回复请求");
        commentService.addReply(reply);
        log.info("新增回复成功");
        return Result.success();
    }

    @GetMapping("/selectComment/{blogId}")
    public Result selectByBlogId(@PathVariable Integer blogId){
        log.info("查看博客评论");
        List<Comment> comments = commentService.selectByBlogId(blogId);
        log.info("查看评论成功");
        return Result.success(comments);
    }

    @GetMapping("/selectReply/{commentId}")
    public Result selectByCommentId(@PathVariable Integer commentId){
        log.info("查看评论的回复");
        List<Reply> list = commentService.selectReply(commentId);
        log.info("查看回复成功");
        return Result.success(list);
    }

}
